package cn.cxyxj.study.webflux02.email;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cxyxj
 */
@Service
public class EmailReactiveUserDetailsService {

   private static Map<String, UserDetails> users = new HashMap(2);
    static {
        users.put("19908488818@163.com", User.withUsername("112@145").password("").roles("dev").build());
        users.put("1918@163.com", User.withUsername("1918@163.com").password("").roles("test").build());
    }

    public Mono<UserDetails> findByEmail(String email) {
        UserDetails userDetails = users.get(email);
        // 构造出一个Mono
        return (userDetails != null) ? Mono.just(userDetails) : Mono.empty();

    }

}
